package graph

import (
	"context"
	"fmt"
	"log"
	"yoga/database"
	"yoga/graph/model"
	"yoga/identify"
)

func (r *queryResolver) User(ctx context.Context, id int32) (*model.User, error) {
	panic(fmt.Errorf("not implemented: User - user"))
}

func (r *queryResolver) Me(ctx context.Context) (*model.Me, error) {
	claims, ok := ctx.Value("claims").(*identify.Claims)
	if !ok {
		log.Fatal("claims not found")
		return nil, fmt.Errorf("claims not found")
	}
	user, err := database.GetUserByID(claims.UserID)
	if err != nil {
		return nil, err
	}
	return user.ToPrivateUser(), nil
}
